/*
 * BBDDefaultRow.java
 *
 * Created on January 20, 2007, 11:53 AM
 *
 * Default implementation of row from stored procedure.
 *

 *
 */

package bbd;
/*
 * Copyright 2007 microneering, Inc and James Gamber
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * BBD/bbd/BBDDefaultRow.java
 */
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.logging.Logger;

/**
 * Default implementation of one row of data returned by the API.
 *
 * To create classes for specific tables, this class should be extended.
 *
 * @param E any class that extends BBDField, such as BBDDefaultField
 * @author james gamber
 */
@SuppressWarnings("serial")
public class BBDDefaultRow<E extends BBDField> extends ArrayList<E> implements BBDRow<E>  {
    
    static final private Logger log = Logger.getLogger(BBDDefaultRow.class
            .getName());
    
    /**
     * Creates a new instance of BBDDefaultRow
     */
    public BBDDefaultRow() {
    	super();
    }
    
    /**
     *
     * @param index
     *            for field requested, starts at 0.
     *
     * @return BBDField at index.
     */
    public E getBBDField(final int index) {
        
        return get(index);
    }
    
    public String getString(final int index) {
        return (String) getBBDField(index).getValue();
    }
    
    public Integer getInteger(final int index) {
        return (Integer) getBBDField(index).getValue();
    }
    
    /**
     * This prevents accidental calls to remove using collection and other
     * objects.
     * @param object Object you want to remove
     * @deprecated don't call remove with an Object type
     */
    @Override
    @Deprecated
    public boolean remove(final Object object) {
        log.severe("do not call remove with Object");
        throw new IllegalArgumentException("do not call remove with Object");
        
    }
    
    /**
     * Remove only BBDField types.
     *
     * Prevents passing other type objects.
     *
     * @param object must be a BBDField
     * @return true if object removed.
     */
    public boolean remove(final E object) {
        return super.remove(object);
    }
    
        /* (non-Javadoc)
         * @see bbd.BBDRow#getDate(int)
         */
    public Date getDate(final int index) {
        return (Date) getBBDField(index).getValue();
    }
    
        /* (non-Javadoc)
         * @see bbd.BBDRow#getTime(int)
         */
    public Time getTime(final int index) {
        return (Time) getBBDField(index).getValue();
    }
    
        /* (non-Javadoc)
         * @see bbd.BBDRow#getTimeStamp(int)
         */
    public Timestamp getTimeStamp(final int index) {
        return (Timestamp) getBBDField(index).getValue();
    }
    
    public E getBBDField(final String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    @Override
	public Object[] toArray() {
        return super.toArray();
    }
    
    public E[] toArray(final E[] a) {
        return super.toArray(a);
    }
    
}
